import 'package:app/common/tool.dart';
import 'package:app/components/base_scaffold_appbar.dart';
import 'package:app/components/bottom_enter_page.dart';
import 'package:app/pages/car_modules/apply_car_module/apply_car_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:get/get_state_manager/src/simple/get_view.dart';
import 'package:get/get.dart';

import '../../../utils/hexcolor.dart';
import '../../../utils/search_module.dart';
class ApplyCarView extends GetView{

  ApplyCarController controller = Get.put(ApplyCarController());

  final GlobalKey<FormState> _formKey = GlobalKey<FormState>();

  bool submit = false;

  @override
  Widget build(BuildContext context) {


    // TODO: implement build
    return Scaffold(
      appBar: BaseAppBar(
        preferredSize: Size(Get.width, AppTool.appBarHEIGHT),
        child: Text('申请用车'),
      ),
      body:GetBuilder<ApplyCarController>(builder: (_){
        return GestureDetector(
          onTap: () {
            /// 页面点击响应
            SearchModule.closeKeyboard(context);
          },
          onPanDown: (_) {
            /// 列表滑动响应
            SearchModule.closeKeyboard(context);
          },
          child:Column(
            children: [
              Expanded(child:ListView(
                children: [

                  GestureDetector(

                      onTap: () async {

                        controller.tapClickCar();

                      },
                      child: Container(
                        padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
                        color: HexColor('#FEFEFE'),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text("选择车辆"),
                            Container(
                                height: 40,
                                child: Row(
                                  mainAxisAlignment:
                                  MainAxisAlignment.spaceAround,
                                  crossAxisAlignment: CrossAxisAlignment.center,
                                  children: [
                                    Text(controller.carName),
                                    const Icon(
                                      Icons.arrow_forward_ios,
                                      size: 15,
                                    )
                                  ],
                                )),
                          ],
                        ),
                      )),
                  SizedBox(height: 1,),
                  submit==false?SizedBox():controller.carID==null?buildFieldError('请选择车辆'):SizedBox(),

                  GestureDetector(
                      onTap: () async {
                        controller.tapClickUser();
                      },
                      child: Container(
                        padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
                        color: HexColor('#FEFEFE'),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text("使用人"),
                            Container(
                                height: 40,
                                child: Row(
                                  mainAxisAlignment:
                                  MainAxisAlignment.spaceAround,
                                  crossAxisAlignment: CrossAxisAlignment.center,
                                  children: [
                                    Text(controller.userIdName[0]),
                                    const Icon(
                                      Icons.arrow_forward_ios,
                                      size: 15,
                                    )
                                  ],
                                )),
                          ],
                        ),
                      )),
                  SizedBox(height: 1,),
                  submit==false?SizedBox():controller.userId==null?buildFieldError('请选择使用人'):SizedBox(),


                  GestureDetector(
                      onTap: () async {
                        controller.tapClickStartTime();
                      },
                      child: Container(
                        padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
                        color: HexColor('#FEFEFE'),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text("开始时间"),
                            Container(
                                height: 40,
                                child: Row(
                                  mainAxisAlignment:
                                  MainAxisAlignment.spaceAround,
                                  crossAxisAlignment: CrossAxisAlignment.center,
                                  children: [
                                    Text(controller.startTime),
                                    const Icon(
                                      Icons.arrow_forward_ios,
                                      size: 15,
                                    )
                                  ],
                                )),
                          ],
                        ),
                      )),
                  SizedBox(height: 1,),
                  GestureDetector(
                      onTap: () async {
                        controller.tapClickEndTime();
                      },
                      child: Container(
                        padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
                        color: HexColor('#FEFEFE'),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text("结束时间"),
                            Container(
                                height: 40,
                                child: Row(
                                  mainAxisAlignment:
                                  MainAxisAlignment.spaceAround,
                                  crossAxisAlignment: CrossAxisAlignment.center,
                                  children: [
                                    Text(controller.endTime),
                                    const Icon(
                                      Icons.arrow_forward_ios,
                                      size: 15,
                                    )
                                  ],
                                )),
                          ],
                        ),
                      )),

                  SizedBox(height: 1,),
                  GestureDetector(
                      onTap: () async {

                      },
                      child: Container(
                        padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
                        color: HexColor('#FEFEFE'),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text("出发地"),
                            Container(
                              // height: 40,
                                padding: EdgeInsets.only(right: 5),
                                width: 150,
                                child: TextField(
                                  textDirection: TextDirection.rtl,
                                  controller: controller.placeStartController,
                                  decoration: InputDecoration(
                                      border: InputBorder.none,
                                      hintText: '出发地',
                                      hintTextDirection: TextDirection.rtl
                                  ),
                                )
                            ),
                          ],
                        ),
                      )),

                  SizedBox(height: 1,),
                  GestureDetector(
                      onTap: () async {

                      },
                      child: Container(
                        padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
                        color: HexColor('#FEFEFE'),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text("目的地"),
                            Container(
                              // height: 40,
                                padding: EdgeInsets.only(right: 5),
                                width: 150,
                                child: TextField(
                                  textDirection: TextDirection.rtl,
                                  controller: controller.placeEndController,
                                  decoration: InputDecoration(
                                      border: InputBorder.none,
                                      hintText: '目的地',
                                      hintTextDirection: TextDirection.rtl
                                  ),
                                )
                            ),
                          ],
                        ),
                      )),

                  SizedBox(height: 1,),
                  GestureDetector(
                      onTap: () {
                        controller.tapClickAccessory(['正常', '加急', '特急']);
                      },
                      child: Container(
                        padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
                        color: HexColor('#FEFEFE'),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text("公开程度"),
                            Container(
                                height: 40,
                                child: Row(
                                  mainAxisAlignment:
                                  MainAxisAlignment.spaceAround,
                                  crossAxisAlignment: CrossAxisAlignment.center,
                                  children: [
                                    Text("${controller.urgency}"),
                                    const Icon(
                                      Icons.arrow_forward_ios,
                                      size: 15,
                                    )
                                  ],
                                )),
                          ],
                        ),
                      )),



                ],
              ),
              ),

              Container(
                color: Colors.white,
                child: BottomEnterPage((){
                  submit = true;
                  controller.update();

                  if(controller.carID!=null&&controller.userId!=null){
                    controller.requestDataWithCreate();
                  }

                }),
              )

            ],
          )



        );
      }),
    );
  }
  Widget buildFieldError(errorType) {
    return Padding(padding: EdgeInsets.only(left: 15),child: Row(
      children: [
        // if(errors.contains(errorType))
        Expanded(
          child: Text(
              '${errorType}',
              textAlign: TextAlign.left,
              style: TextStyle(
                  color: Colors.red,
                  fontSize: 12
              )
          ),
        ),
      ],
    ),);
  }

}